package com.steakliu.sun.buffer.api;

import io.netty.channel.ChannelHandlerContext;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 功能说明：
 * <p>
 * Original @Author: steakliu-刘牌, 2023-02-09  13:30
 * <p>
 * Copyright (C)2020-2022  steakliu All rights reserved.
 */
public class DataBufferChannelManager {

    private final Map<Long, ChannelHandlerContext> MAP = new ConcurrentHashMap<>();

    private static volatile DataBufferChannelManager dataBufferChannelManager;

    public static DataBufferChannelManager getInstance(){
        if (null == dataBufferChannelManager){
            synchronized (DataBufferChannelManager.class){
                if (null == dataBufferChannelManager){
                    dataBufferChannelManager =  new DataBufferChannelManager();
                }
            }
        }
        return dataBufferChannelManager;
    }

    public void add(Long requestId, ChannelHandlerContext context){
        MAP.put(requestId, context);
    }

    public ChannelHandlerContext get(Long requestId){
        return MAP.get(requestId);
    }

    public ChannelHandlerContext remove(Long requestId){
        return MAP.remove(requestId);
    }
}
